//
//  HWGrowthPathCell.swift
//  HWanGame
//
//  Created by 王昌健 on 2022/6/28.
//  Copyright © 2022 94hwan. All rights reserved.
//

import UIKit

class HWGrowthPathCell: UITableViewCell {
    var bgView:UIView!
    var titleLabel:UILabel!
    var contentLabel:UILabel!
    var integralLabel:UILabel!
    var rightButton:UIButton!
    var model:HWGrowthPathModel?{
        didSet {
            titleLabel.text = model?.name
            contentLabel.text = model?.content
            integralLabel.text = "+\(model?.points ?? "") 积分"
            if model?.status == 0{
                rightButton.setTitle("未完成", for: .normal)
                rightButton.layer.borderWidth = 1
                rightButton.layer.borderColor = UIColor.colorWithHexString(hexString: "#CCCCCC").cgColor
                rightButton.backgroundColor = .colorWithHexString(hexString: "#CCCCCC")
                rightButton.setTitleColor(.white, for: .normal)
            } else if model?.status == 1 {
                rightButton.setTitle("已完成", for: .normal)
                rightButton.layer.borderWidth = 1
                rightButton.layer.borderColor = UIColor.colorWithHexString(hexString: "#F7F7F7").cgColor
                rightButton.backgroundColor = .colorWithHexString(hexString: "#F7F7F7")
                rightButton.setTitleColor(.colorWithHexString(hexString: "#CCCCCC"), for: .normal)
            } else {
                
            }
        }
    }
    class func cellWithTableView(tableView:UITableView) -> (HWGrowthPathCell) {
        let reUse:String = "HWGrowthPathCell"
        
        var cell = tableView.dequeueReusableCell(withIdentifier: reUse)
        
        if cell == nil {
            cell = HWGrowthPathCell.init(style: UITableViewCell.CellStyle.default, reuseIdentifier: reUse)
        }
        
        return cell as! HWGrowthPathCell
    }
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        initUI()
        initFrame()
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
    }
    
    func initUI() -> Void {
        selectionStyle = UITableViewCell.SelectionStyle.none
        backgroundColor = UIColor.clear
        
        bgView = UIView()
        bgView.backgroundColor = .white
        bgView.layer.cornerRadius = 18*widthScale
        contentView.addSubview(bgView)
        
        bgView.layer.shadowColor = UIColor.colorWithAlphaHexString(hexString: "#E7E7E7", alpha: 0.42).cgColor
        bgView.layer.shadowOffset = CGSize(width: 0, height: 0)
        bgView.layer.shadowOpacity =  1
        bgView.layer.shadowRadius = 11*widthScale

        titleLabel = HWLabel.createBoldLabel(title: "", color: "#333333", font: 16*widthScale)
        titleLabel.font = .systemFont(ofSize: 16*widthScale, weight: .semibold)
        bgView.addSubview(titleLabel)
        
        contentLabel = HWLabel.createLabel(title: "", color: "#888888", font: 13*widthScale)
        bgView.addSubview(contentLabel)
        
        integralLabel = HWLabel.createLabel(title: "", color: "#FA8C08", font: 11*widthScale)
        bgView.addSubview(integralLabel)
        
        rightButton = UIButton(type: .custom)
        rightButton.layer.cornerRadius = 14*widthScale
        rightButton.layer.masksToBounds = true
        rightButton.titleLabel?.font = .systemFont(ofSize: 13*widthScale, weight: .semibold)
        bgView.addSubview(rightButton)
    }
    
    func initFrame() -> Void {
        bgView.snp.makeConstraints { make in
            make.top.equalTo(9*widthScale)
            make.left.equalTo(18*widthScale)
            make.right.equalTo(-18*widthScale)
            make.bottom.equalToSuperview()
        }
        
        titleLabel.snp.makeConstraints { make in
            make.left.top.equalTo(18*widthScale)
            make.height.equalTo(23*widthScale)
            make.right.equalTo(rightButton.snp.left).offset(-18*widthScale)
        }
        
        contentLabel.snp.makeConstraints { make in
            make.left.equalTo(18*widthScale)
            make.height.equalTo(18*widthScale)
            make.right.equalTo(titleLabel)
            make.bottom.equalTo(-18*widthScale)
            make.top.equalTo(titleLabel.snp.bottom).offset(4*widthScale)
        }
        
        integralLabel.snp.makeConstraints { make in
            make.top.equalTo(16*widthScale)
            make.right.equalTo(-15*widthScale)
            make.height.equalTo(15*widthScale)
        }
        
        rightButton.snp.makeConstraints { make in
            make.height.equalTo(28*widthScale)
            make.width.equalTo(54*widthScale)
            make.top.equalTo(integralLabel.snp.bottom).offset(4*widthScale)
            make.right.equalTo(-14*widthScale)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
